<html>
<head>
	<title>Sub District</title>
</head>
<body>
	<?php
	
		include_once("adb.php");
		
		class subdistrict extends adb{
			
			function subdistrict(){
				adb::adb();
			}
			
			function get_subdistrict($_id){
				$query = "SELECT * FROM subdistrict WHERE subdistrict_id = '$_id'";
				
				return $this->query($query);
			}
			
			function list_all(){ //lists all subdistricts
				$query = "SELECT * FROM subdistrict";
				
				return $this->query($query);
			}
			
			function insert_into_subdistrict($_name, $_district_id){ //allows to add new subdistrict to list
				$query = "INSERT INTO subdistrict (subdistrict_name, district_id) VALUES ('$_name', '$_district_id')";
				
				return $this->query($query);
			}
			
			function delete_row($_id){ //deletes a row in a given table
				$query = "DELETE FROM subdistrict WHERE subdistrict_id = '$_id'";
				
				return $this->query($query);
			}
			
			function edit_subdistrict($_id, $_name, $_district_id){ //allows to edit subdistrict information
				$query = "UPDATE subdistrict SET subdistrict_name = $_name, district_id = $_district_id WHERE subdistrict_id = $_id";
				
				return $this->query($query);				
			}
			
			function search($_name){ //lists all subdistricts with the name given
				$query = "SELECT * FROM subdistrict WHERE subdistrict_name LIKE '%$_name%'";
				
				return $this->query($query);
			}
			
			function sub_per_district($_district_id){ //lists all the subdistricts under the district ID selected
				$query = "SELECT * FROM subdistrict WHERE district_id = $_district_id";
				
				return $this->query($query);
			}
			
			function sub_per_CHO($_name){ //lists all CHOs from the subdistrict selected
				$query = "SELECT cho_name FROM cho, subdistrict WHERE subdistrict.subdistrict_id = cho.subdistrict_id AND subdistrict_name = $_name";
				
				return $this->query($query);
			}
		}
		
	?>
</body>
</html>
